<template>
    <div class="xsglAdd">
<el-form ref="form" :model="form" label-width="80px" :rules="rules">
  <el-form-item label="课程名" prop="name">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
  <el-form-item label="授课教师" prop="teacherId">
     <el-select filterable v-model="form.teacherId" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.name"
      :value="item.id">
    </el-option>
  </el-select>
  </el-form-item>
  <el-form-item label="年级" prop="grade">
    <el-input v-model="form.grade"></el-input>
  </el-form-item>
  <el-form-item label="上课时间">
     <el-select filterable v-model="form.week" placeholder="请选择">
    <el-option label="星期一" value="1"></el-option>
    <el-option label="星期二" value="2"></el-option>
    <el-option label="星期三" value="3"></el-option>
    <el-option label="星期四" value="4"></el-option>
    <el-option label="星期五" value="5"></el-option>
    <el-option label="星期六" value="6"></el-option>
    <el-option label="星期日" value="7"></el-option>
  </el-select>
     <el-select filterable v-model="form.lesson" placeholder="请选择">
    <el-option label="第一节" value="1"></el-option>
    <el-option label="第二节" value="2"></el-option>
    <el-option label="第三节" value="3"></el-option>
    <el-option label="第四节" value="4"></el-option>
    <el-option label="第五节" value="5"></el-option>
    <el-option label="第六节" value="6"></el-option>
    <el-option label="第七节" value="7"></el-option>
    <el-option label="第八节" value="8"></el-option>
    <el-option label="第九节" value="9"></el-option>
  </el-select>
  </el-form-item>
  <el-form-item label="时长(节)" prop="duration">
    <el-input-number v-model="form.duration" controls-position="right" :min="1" :max="10"></el-input-number>
  </el-form-item>
  <el-form-item label="上课地点" prop="location">
    <el-input v-model="form.location "></el-input>
  </el-form-item>
  <el-form-item label="学分" prop="credit">
    <el-input-number v-model="form.credit" controls-position="right" :min="1" :max="10"></el-input-number>
  </el-form-item>
  <el-form-item label="最大容量" prop="maxSize">
    <el-input-number v-model="form.maxSize" controls-position="right" :min="1" :max="100"></el-input-number>
  </el-form-item>
  <el-form-item label="考试地点" prop="examLocation">
    <el-input v-model="form.examLocation "></el-input>
  </el-form-item>
  
   
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button @click="handleClose">取消</el-button>
  </el-form-item>
</el-form>
    </div>
</template>

<script>
import {kcglAdd,departmentAll} from "@/api/kcgl"
  export default {
    data() {
      return {
        form: {
          name: '',
          id:-1,
          teacherId :"",
          grade:"",
          week:"1",
          lesson:"1",
          duration:"1",
          location:"",
          maxSize:50,
          examLocation:""
        },
        rules: {
                name: [
                    { required: true, message: '请输入专业名称', trigger: 'blur' },
                ],
            },
            options:[{

            }]
      }
    },
    methods: {
      onSubmit() {
        console.log('submit!');
         this.$refs['form'].validate(flag => {
          this.form.time=[this.form.week,this.form.lesson,this.form.duration].join("-")
            if(flag){
                console.log(this.form);
                kcglAdd(this.form).then(res=>{
                  console.log(res);
                  if(res.code===0){
                    this.$message({
                      message:"添加成功",
                      type:"success",
                      duration:1000
                    })
                    this.$emit("done")
                  }
                  
                })
                
            }
         })
      },
      handleClose(){
        this.$emit("close")
      },
      //获取系列表
      getList(){
        departmentAll().then(res=>{
          console.log(res);
          if(res.code===0){
            this.options=res.data
          }
        })
      }
    },
    mounted(){
      this.getList()
    }

  }
</script>